#include <QMessageBox>
#include "mvc/view/param_widget_uav.h"
#include "ui_param_widget_uav.h"
#include "mvc/view/airfoil_dialog.h"
#include "mvc/view/configuration_dialog.h"
#include "mvc/model/aircrafts/aircraft_rcurves.h"
#include "mvc/model/aircrafts/aircraft_parameters.h"
#include "common/types.h"
#include "common/settings.h"
#include "common/modules.h"

Param_widget_uav::Param_widget_uav(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Param_widget_uav)
{
    ad = new Airfoil_dialog(this);
    af_reference_curve = new Airfoils_curve_map();
    ui->setupUi(this);
    closed = false;
    load_images();
    set_reg_exp_default();
    set_signal_buttons();
    mapping_lineEdit();
    charge_test();
}

Param_widget_uav::~Param_widget_uav()
{
    delete ui;
    closed = true;
}

Airfoil_dialog *Param_widget_uav::get_airfoil_dialog()
{
    return ad;
}

/*
 * Set text on the widget
 */
void Param_widget_uav::retranslateUi(){
    ui->retranslateUi(this);
}

/**
 * @brief Param_widget_uav::getClosed
 * @return value of atribute 'closed'
 */
bool Param_widget_uav::getClosed(){
    return closed;
}

/**
 * Set the action of each button.
 */
void Param_widget_uav::set_signal_buttons()
{
    // BOTONES DE TRANSICION DE IMAGENES
    connect(ui->front_view_wing_button, SIGNAL(clicked()), this, SLOT(front_view_wing_clicked()));
    connect(ui->top_view_wing_button, SIGNAL(clicked()), this, SLOT(top_view_wing_clicked()));
    // BOTON ACEPTAR

    connect(ui->ok_button, SIGNAL(clicked()), this, SLOT(control_parameteres()));
    // CONECTAR BOTONES DE PERFILES ALARES
    connect(ui->fwing_airfoil_button, SIGNAL(clicked()), this, SLOT(load_fwing_button()));
    connect(ui->bwing_airfoil_button, SIGNAL(clicked()), this, SLOT(load_bwing_button()));
    connect(ui->lwing_airfoil_button, SIGNAL(clicked()), this, SLOT(load_lwing_button()));
    connect(ui->wingtip_airfoil_button, SIGNAL(clicked()), this, SLOT(load_wingtip_button()));
    connect(ui->radioButton_1, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_2, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_3, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_4, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_5, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_6, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_7, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_8, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_9, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_10, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_11, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_12, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_13, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_14, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_15, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_16, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_17, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_18, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_19, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_20, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_21, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_22, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_23, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_24, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_25, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_26, SIGNAL(clicked()), this, SLOT(set_range_pressed()));
    connect(ui->radioButton_27, SIGNAL(clicked()), this, SLOT(set_range_pressed()));

    //

}


/**
*  Action when bwing_button is pressed.
*/
void Param_widget_uav::load_bwing_button()
{
    //std::cout << "load bwing button" << std::endl;
    show_airfoil_dialog();
    last_button_pressed = BWING;
}
/**
*  Action when fwing_button is pressed.
*/
void Param_widget_uav::load_fwing_button()
{
    //std::cout << "load fwing button" << std::endl;
    show_airfoil_dialog();
    last_button_pressed = FWING;
}

/**
*  Action when lwing_button is pressed.
*/
void Param_widget_uav::load_lwing_button()
{
    //std::cout << "load lwing button" << std::endl;
    show_airfoil_dialog();
    last_button_pressed = LWING;
}

/**
*  Action when wingtip_button is pressed.
*/
void Param_widget_uav::load_wingtip_button()
{
    //std::cout << "load wingtip button" << std::endl;
    show_airfoil_dialog();
    last_button_pressed = WINGTIP;
}

/**
*  Set the file name of bwing parameter in the file edit.
*/
void Param_widget_uav::set_bwing(QString file_name)
{
    ui->bwing->setText(file_name);
}

/**
*  Set the file name of fwing parameter in the file edit.
*/
void Param_widget_uav::set_fwing(QString file_name)
{
    ui->fwing->setText(file_name);
}

/**
*  Set the file name of lwing parameter in the file edit.
*/
void Param_widget_uav::set_lwing(QString file_name)
{
    ui->lwing->setText(file_name);
}

/**
*  Set the file name of wingtip parameter in the file edit.
*/
void Param_widget_uav::set_wingtip(QString file_name)
{
    ui->wingtip->setText(file_name);
}
/**
 * Set a regular expression for each line edit.
 */
void Param_widget_uav::set_reg_exp_default()
{
    //QRegExp regExpInteger("([1-9][0-9]*)(-([1-9][0-9]*),([1-9][0-9]*))?");
    //fuselage
    ui->l->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->d->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->xfa->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->npf->setValidator(new QIntValidator(0, 999, this)) ;
    ui->xnfs->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->dt->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->lt->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    //wing
    ui->ct->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->cj->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->crf->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->cra->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->npc->setValidator(new QIntValidator(0, 999, this)) ;
    ui->sob->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->sib->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->d_ob->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->d_ib->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->l_ob->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->l_ib->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->arf->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->ara->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->aj->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->at->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    //empennage
    ui->zfa->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->npev->setValidator(new QIntValidator(0, 999, this)) ;
    //snout
    ui->ln->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->dn->setValidator(new QDoubleValidator(0.0, 999.0, 5, this));
    ui->npm->setValidator(new QIntValidator(0, 999, this)) ;
}

void Param_widget_uav::set_reg_exp_range_double(QLineEdit *lineEdit){
    QRegExp regExpRange("(0|[1-9][0-9]*)\\.[0-9]+(\\-(0|[1-9][0-9]*)\\.[0-9]+\\,(0|[1-9][0-9]*)\\.[0-9]+)?");
    //         |       double           | - |     double             |, |         double       |
    lineEdit->setValidator(new QRegExpValidator(regExpRange,this));
}

void Param_widget_uav::set_reg_exp_range_int(QLineEdit *lineEdit){
    QRegExp regExpRange("(0|[1-9][0-9]*)\\-(0|[1-9][0-9]*)\\,(0|[1-9][0-9]*)");
    //         |       double           | - |     double             |, |         double       |
    lineEdit->setValidator(new QRegExpValidator(regExpRange,this));
}

void Param_widget_uav::get_widget_parameters()
{
    ParametersWidget *pw = new ParametersWidget();

    //fuselage
    QMap<QString, QString> fuselageParameters;
    fuselageParameters.insert(fuselage_ln, ui->ln->text());
    fuselageParameters.insert(fuselage_l, ui->l->text());
    fuselageParameters.insert(fuselage_lt, ui->lt->text());
    fuselageParameters.insert(fuselage_dn, ui->dn->text());
    fuselageParameters.insert(fuselage_d, ui->d->text());
    fuselageParameters.insert(fuselage_dt, ui->dt->text());
    fuselageParameters.insert(fuselage_npm, ui->npm->text());
    fuselageParameters.insert(fuselage_npf, ui->npf->text());
    fuselageParameters.insert(fuselage_xnfs, ui->xnfs->text());
    pw->insert(s_fuselage, fuselageParameters);

    //wing
    QMap<QString, QString> wingParameters;
    wingParameters.insert(wings_ct, ui->ct->text());
    wingParameters.insert(wings_cj, ui->cj->text());
    wingParameters.insert(wings_crf, ui->crf->text());
    wingParameters.insert(wings_npc, ui->npc->text());
    wingParameters.insert(wings_sob, ui->sob->text());
    wingParameters.insert(wings_sib, ui->sib->text());
    wingParameters.insert(wings_dob, ui->d_ob->text());
    wingParameters.insert(wings_dib, ui->d_ib->text());
    wingParameters.insert(wings_lob, ui->l_ob->text());
    wingParameters.insert(wings_lib, ui->l_ib->text());
    wingParameters.insert(wings_arf, ui->arf->text());
    wingParameters.insert(wings_aj, ui->aj->text());
    wingParameters.insert(wings_at, ui->at->text());
    pw->insert(s_wings, wingParameters);

    //empennage
    QMap<QString, QString> empennageParameters;
    empennageParameters.insert(vtail_zfa, ui->zfa->text());
    empennageParameters.insert(vtail_npev, ui->npev->text());
    pw->insert(s_vertical_tail, empennageParameters);

    //htail
    QMap<QString, QString> htailParameters;
    htailParameters.insert(htail_xfa, ui->xfa->text());
    htailParameters.insert(htail_ara, ui->ara->text());
    htailParameters.insert(htail_cra, ui->cra->text());
    pw->insert(s_horizontal_tail, htailParameters);

    //airfoil
    QMap<QString, QString> airfoils;
    airfoils.insert(wings_root, ui->fwing->text());
    airfoils.insert(wings_join, ui->lwing->text());
    airfoils.insert(wings_wingtip, ui->wingtip->text());
    airfoils.insert(htail_root, ui->bwing->text());
    pw->insert("airfoils",airfoils);

    emit s_load_parameters(pw, af_reference_curve, get_module_value(uavs_jw_module));
}
/**
 * @brief Param_widget_uav::control_param
 * controls every required field of the widget.
 * @return true, if all field are correctly completed.
 *         false, otherwise.
 */
bool Param_widget_uav::control_param()
{
    if(ui->l->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'L' field is empty"));
        return false;
    }

    if(ui->lt->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'Lt' field is empty"));
        return false;
    }

    if(ui->d->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'd' field is empty"));
        return false;
    }

    if(ui->xfa->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'xfa' field is empty"));
        return false;
    }

    if(ui->npf->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'npf' field is empty"));
        return false;
    }

    if(ui->xnfs->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'xnfs' field is empty"));
        return false;
    }
    if(ui->dt->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'dt' field is empty"));
        return false;
    }

    if(ui->lt->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'lt' field is empty"));
        return false;
    }

    if(ui->ct->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'ct' field is empty"));
        return false;
    }

    if(ui->cj->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'cj' field is empty"));
        return false;
    }

    if(ui->crf->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'crf' field is empty"));
        return false;
    }

    if(ui->cra->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'cra' field is empty"));
        return false;
    }

    if(ui->npc->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'npc' field is empty"));
        return false;
    }


    if(ui->sob->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'Sob' field is empty"));
        return false;
    }

    if(ui->sib->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'Sib' field is empty"));
        return false;
    }

    if(ui->d_ob->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'δob' field is empty"));
        return false;
    }

    if(ui->d_ib->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'δib' field is empty"));
        return false;
    }

    if(ui->l_ob->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'Λob' field is empty"));
        return false;
    }

    if(ui->l_ib->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'Λib' field is empty"));
        return false;
    }

    if(ui->arf->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'arf' field is empty"));
        return false;
    }

    if(ui->ara->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'ara' field is empty"));
        return false;
    }

    if(ui->aj->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'aj' field is empty"));
        return false;
    }

    if(ui->at->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'at' field is empty"));
        return false;
    }

    if(ui->bwing->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'HTail root' field is empty"));
        return false;
    }
    else
    {
        if(!valid_file(ui->bwing->text()))
        {
            QMessageBox::warning(this, tr("Warning"), tr("'HTail root'. File not valid"));
            return false;
        }
    }

    if(ui->fwing->text()=="")
    {
        QMessageBox::warning(this, tr("Warning"), tr("The 'Wing' field is empty"));
        return false;
    }
    else
    {
        if(!valid_file(ui->fwing->text()))
        {
            QMessageBox::warning(this, tr("Warning"), tr("'Wing'. File not valid"));
            return false;
        }
    }

    if(ui->lwing->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'Join of wings' field is empty"));
        return false;
    }
    else
    {
        if(!valid_file(ui->lwing->text()))
        {
            QMessageBox::warning(this, tr("Warning"), tr("'Join of wings'. File not valid"));
            return false;
        }
    }

    if(ui->wingtip->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'Wingtip' field is empty"));
        return false;
    }
    else
    {
        if(!valid_file(ui->wingtip->text()))
        {
            QMessageBox::warning(this, tr("Warning"), tr("'Wingtip'. File not valid"));
            return false;
        }
    }

    if(ui->zfa->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'zfa' field is empty"));
        return false;
    }

    if(ui->npev->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'npev' field is empty"));
        return false;
    }

    if(ui->ln->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'Ln' field is empty"));
        return false;
    }

    if(ui->dn->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'dn' field is empty"));
        return false;
    }
    if(ui->npm->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'npm' field is empty"));
        return false;
    }
    return true;
}

/**
 * @brief Param_widget_uav::valid_file
 * @param nameFile: name of a file to control.
 * @return true, if the namefile already exists
 *         false, otherwise.
 */
bool Param_widget_uav::valid_file(QString nameFile)
{
    QString path = airfoils_directory();
    path.append("/");
    path.append(nameFile);

    QFile file(path);
    if (!file.open(QIODevice::ReadOnly))
    {
        std::cerr << "Cannot open the file (Param widget::invalide file): " << path.toStdString() <<std::endl;
        file.close();
        return false;
    }

    file.close();

    return true;
}


/**
  * Load the images of each tab.
  */
void Param_widget_uav::load_images()
{
    //Fuselage tab
    QImage image_fuselage(":images/UAV_fuselage.png");
    ui->uav_fuselage_image->setPixmap(QPixmap::fromImage(image_fuselage));
    ui->uav_fuselage_image->setScaledContents(true);

    QImage image_parameters_lateral_view_fuselage(":images/UAV_lateral_view_fuselage.png");
    ui->uav_fuselage_lateral_view_image->setPixmap(QPixmap::fromImage(image_parameters_lateral_view_fuselage));
    ui->uav_fuselage_lateral_view_image->setScaledContents(true);

    //Wing tab
    QImage image_wing(":images/UAV_wings.png");
    ui->uav_wing_image->setPixmap(QPixmap::fromImage(image_wing));
    ui->uav_wing_image->setScaledContents(true);

    QImage image_parameters_top_view_wing(":images/UAV_top_view_wing.png");
    ui->uav_wing_top_view_image->setPixmap(QPixmap::fromImage(image_parameters_top_view_wing));
    ui->uav_wing_top_view_image->setScaledContents(true);

    //Tail tab
    QImage image_tail(":images/UAV_tail.png");
    ui->uav_tail_image->setPixmap(QPixmap::fromImage(image_tail));
    ui->uav_tail_image->setScaledContents(true);

    QImage image_parameters_front_view_tail(":images/UAV_front_view_tail.png");
    ui->uav_tail_front_view_image->setPixmap(QPixmap::fromImage(image_parameters_front_view_tail));
    ui->uav_tail_front_view_image->setScaledContents(true);

    //Nose tab
    QImage image_nose(":images/UAV_nose.png");
    ui->uav_nose_image->setPixmap(QPixmap::fromImage(image_nose));
    ui->uav_nose_image->setScaledContents(true);

    QImage image_parameters_lateral_view_nose(":images/UAV_lateral_view_nose.png");
    ui->uav_nose_lateral_view_image->setPixmap(QPixmap::fromImage(image_parameters_lateral_view_nose));
    ui->uav_nose_lateral_view_image->setScaledContents(true);
}

/**
* Actions when top_view button in wing tab is clicked.
*/
void Param_widget_uav:: top_view_wing_clicked()
{
    ui->uav_wing_front_view_image->clear();
    //            ->setPixmap(NULL);
    QImage image_parameters_wing(":images/UAV_top_view_wing.png");
    ui->uav_wing_top_view_image->setPixmap(QPixmap::fromImage(image_parameters_wing));
    ui->uav_wing_top_view_image->setScaledContents(true);
}

/**
* Actions when front_view button in wing tab is clicked.
*/
void Param_widget_uav:: front_view_wing_clicked()
{
    ui->uav_wing_top_view_image->clear();
    //            ->setPixmap(NULL);
    QImage image_parameters_wing(":images/UAV_front_view_wing.png");
    ui->uav_wing_front_view_image->setPixmap(QPixmap::fromImage(image_parameters_wing));
    ui->uav_wing_front_view_image->setScaledContents(true);
}

/**
*  Open a new window 'Airfoil_dialog'
*/
void Param_widget_uav::show_airfoil_dialog()
{

    ad->show();
}

/**
  * Open a new window 'Configuration_dialog'
  */
void Param_widget_uav::control_parameteres()
{
    if(control_param())
    {
        this->close();
        closed = true;
        std::cout << "closed true cuando cierro" << std::endl;
        get_widget_parameters();
    }
}
/**
 * @brief Param_widget_uav::set_range_pressed
 * Disable the another buttons that not checked and change regular expresion for line edit
 */
void Param_widget_uav::set_range_pressed(){

    QMap<QRadioButton *, QLineEdit *>::iterator i, j;
    QString LineEdit_name;
    for (i = index_uavParameters.begin(); i != index_uavParameters.end(); ++i){
        if (i.key()->isChecked()){
            for (j = index_uavParameters.begin(); j != index_uavParameters.end(); ++j) {
                j.key()->setAutoExclusive(false);
                j.key()->setChecked(false);
                j.key()->setDisabled(true);
                set_reg_exp_default();
            }
            charge_test();
            i.key()->setChecked(true);
            i.key()->setEnabled(true);
            LineEdit_name = i.value()->objectName();
            if(LineEdit_name == "npf" || LineEdit_name == "npc" || LineEdit_name == "npev" || LineEdit_name == "npm")
                set_reg_exp_range_int(i.value());
            else
                set_reg_exp_range_double(i.value());

            break;
        }
        else {
            for (j = index_uavParameters.begin(); j != index_uavParameters.end(); ++j) {
                j.key()->setEnabled(true);
            }
        }
    }
}


void Param_widget_uav::mapping_lineEdit(){

    index_uavParameters.insert(ui->radioButton_1, ui->l);
    index_uavParameters.insert(ui->radioButton_2, ui->lt);
    index_uavParameters.insert(ui->radioButton_3, ui->d);
    index_uavParameters.insert(ui->radioButton_4, ui->dt);
    index_uavParameters.insert(ui->radioButton_5, ui->npf);
    index_uavParameters.insert(ui->radioButton_6, ui->xnfs);
    index_uavParameters.insert(ui->radioButton_7, ui->ct);
    index_uavParameters.insert(ui->radioButton_8, ui->cj);
    index_uavParameters.insert(ui->radioButton_9, ui->crf);
    index_uavParameters.insert(ui->radioButton_10, ui->cra);
    index_uavParameters.insert(ui->radioButton_11, ui->sob);
    index_uavParameters.insert(ui->radioButton_12, ui->sib);
    index_uavParameters.insert(ui->radioButton_13, ui->d_ob);
    index_uavParameters.insert(ui->radioButton_14, ui->d_ib);
    index_uavParameters.insert(ui->radioButton_15, ui->l_ob);
    index_uavParameters.insert(ui->radioButton_16, ui->l_ib);
    index_uavParameters.insert(ui->radioButton_17, ui->arf);
    index_uavParameters.insert(ui->radioButton_18, ui->aj);
    index_uavParameters.insert(ui->radioButton_19, ui->ara);
    index_uavParameters.insert(ui->radioButton_20, ui->at);
    index_uavParameters.insert(ui->radioButton_21, ui->xfa);
    index_uavParameters.insert(ui->radioButton_22, ui->npc);
    index_uavParameters.insert(ui->radioButton_23, ui->zfa);
    index_uavParameters.insert(ui->radioButton_24, ui->npev);
    index_uavParameters.insert(ui->radioButton_25, ui->ln);
    index_uavParameters.insert(ui->radioButton_26, ui->dn);
    index_uavParameters.insert(ui->radioButton_27, ui->npm);
}

/**
 * @brief Param_widget_uav::charge_test
 * Set some values to the field to test the widget
 */
void Param_widget_uav::charge_test()
{

    ui->l->setText("40.0");
    ui->d->setText("4.0");
    ui->xfa->setText("30.0");
    ui->npf->setText("5");
    ui->xnfs->setText("9.0");
    ui->dt->setText("0.5");
    ui->ara->setText("0");
    ui->lt->setText("2.5");
    ui->ct->setText("2.5");
    ui->cj->setText("2.5");
    ui->crf->setText("2.5");
    ui->cra->setText("2.5");
    ui->npc->setText("5");
    ui->sob->setText("6.25");
    ui->sib->setText("26.00");
    ui->d_ob->setText("20.0");
    ui->d_ib->setText("15.0");
    ui->l_ob->setText("30.0");
    ui->l_ib->setText("30.0");
    ui->arf->setText("0");
    ui->aj->setText("0");
    ui->at->setText("0");
    ui->zfa->setText("7.00");
    ui->npev->setText("7");
    ui->ln->setText("4.0");
    ui->dn->setText("0.7");
    ui->npm->setText("3");
    ui->ct->setText("2.5");

    ui->fwing->setText("ag04.dat");
    QString path_one(airfoils_directory());
    path_one.append("ag04.dat");
    ad->calc_reference_curve(path_one);
    af_reference_curve->insert(wings_root, ad->get_reference_curve());

    ui->bwing->setText("ag08.dat");
    QString path_two(airfoils_directory());
    path_two.append("ag08.dat");
    ad->calc_reference_curve(path_two);
    af_reference_curve->insert(htail_root, ad->get_reference_curve());

    ui->lwing->setText("ag09.dat");
    QString path_three(airfoils_directory());
    path_three.append("ag09.dat");
    ad->calc_reference_curve(path_three);
    af_reference_curve->insert(wings_join, ad->get_reference_curve());

    ui->wingtip->setText("ag10.dat");
    QString path_four(airfoils_directory());
    path_four.append("ag10.dat");
    ad->calc_reference_curve(path_four);
    af_reference_curve->insert(wings_wingtip,ad->get_reference_curve());
}


/**
*  Load the values selected of airfoil window.
*/
void Param_widget_uav::load_airfoil_value(QVector<Point*> point_list,
                                          QString file_name, int button_pressed)
{
    //std::cout << file_name.toStdString() << std::endl;

    switch (button_pressed)
    {
    case BWING :    ui->bwing->setText(file_name);
        af_reference_curve->insert(htail_root, point_list);
        break;
    case FWING :    ui->fwing->setText(file_name);
        af_reference_curve->insert(wings_root, point_list);
        break;
    case LWING :    ui->lwing->setText(file_name);
        af_reference_curve->insert(wings_join, point_list);
        break;
    case WINGTIP :  ui->wingtip->setText(file_name);
        af_reference_curve->insert(wings_wingtip, point_list);
        break;
    }
}
